/*
public class Test {
    public static  void  addLast(int val){
        ListNode listNode = new ListNode(val);
        //遍历找到tail
        if(head == null){
            head = node;
            return;
        }
        ListNode cur = head;
        while (cur != null){
            cur = cur.next;
        }
        //尾插
        cur.next = node;
    }
    public void addIndex(int index,int val) {
    //1.判断index的合法性
    if (index < 0 || index > size()){
        return;
    }
    //2.index == 0  || index == size()
    if(index == 0){
        addFirst(val);
        return;
    }
    if (index == size()){
        addLast(val);
        return;
    }
    //3. 找到index的前一个位置
        ListNode cur = findIndexSubOne(index);
    //4. 进行连接
    ListNode node = new ListNode(val);
    node = cur.next;
    cur = node;
    }
    private ListNode findIndexSubOne(int index) {
        ListNode cur = head;
        for (int i = 0; i < index; i++) {
            cur = cur.next;
        }
        return cur;
    }
    private checkIndexLegal throws IndexNotLegalException(){
        if(index < 0 || index){
            throw new IndexNotLegalException("index位置不合法")
        }
    }
    public static void main(String[] args) {

    }
}
*/
